<template>
  <div style="padding: 10px">
    <el-table :data="tableData"   stripe style="width: 100%">
      <el-table-column type="index" width="50"  label="序号"/>

      <!--      <el-table-column fixed prop="id" sortable label="ID" width="150"/>-->
      <el-table-column label="订单号" width="240">
        <template #default="scope" >
          <el-button type="text" @click="getOrderDetail(scope.row)"
          >{{scope.row.orderId}}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column  label="创建时间" prop="createTime" width="240"/>

      <el-table-column label="订单状态" width="120" >
        <template #default="scope">
          <view v-if="scope.row.flag==0"><el-button type="info"  >待处理</el-button></view>
          <view v-if="scope.row.flag==1"><el-button type="primary"  >已发货</el-button></view>
          <view v-if="scope.row.flag==2"><el-button type="warning"  >暂存（待补发货）</el-button></view>
          <view v-if="scope.row.flag==3"><el-button type="danger"  >已退货</el-button></view>
        </template>

      </el-table-column>

    </el-table>

    <el-dialog v-model="dialogFormVisible" title="订单详情" width="50%">
      <el-table :data="tableData2"   stripe style="width: 100%">
      <el-table-column label="订单号" width="240">
        <template #default="scope" >
          <el-button type="text" @click="dialogFormVisible = true"
          >{{scope.row.orderId}}</el-button
          >
        </template>
      </el-table-column>
        <el-table-column prop="carPartsName" label="汽车配件名称" width="120"/>
        <el-table-column prop="standard" label="规格" width="120"/>
        <el-table-column prop="carNumber" label="配件编号" width="120"/>

        <el-table-column prop="price" label="价格" width="120"/>
        <el-table-column prop="buy_number" label="购买数量" width="120"/>
      </el-table>
    </el-dialog>
  </div>

</template>

<script>
import request from "@/utils/request";

export default {
  name: "DispatchOrder",
    data(){
    let sum_price=0;
    let userId=JSON.parse(sessionStorage.getItem("user")).id;
    return {
      userId,
      tableData: [],
      tableData2:[],
      sum_price,
      dialogFormVisible:false
    }
  },
  created() {

    this.load()
  },
  methods:{
    load() {
      request.get("/order_form/1").then(res => {
        console.log(res)
        this.tableData = res.data
        for(let i=0;i<this.tableData.length;i++){
          this.tableData[i].createTime=this.tableData[i].createTime.substring(0,19)
          this.tableData[i].createTime=this.tableData[i].createTime.replace("T","--")
        }
      })

    },
    getOrderDetail(row){
      this.dialogFormVisible = true
      request.get("/order_detail/by_orderId/"+row.orderId).then(res=>{
        console.log(res)
        this.tableData2=res.data
      })
    }
  }
}
</script>

<style scoped>

</style>
